#include "globalconnectionmanager.h"

GlobalConnectionManager globManager;

GlobalConnectionManager::GlobalConnectionManager(QObject *parent) :
    QObject(parent)
{
}

void GlobalConnectionManager::readData(sockTypes type,const QByteArray &data)
{

}

void GlobalConnectionManager::newConnection(Connection *pConnection)
{
    connections[pConnection->getSockType()] = pConnection;
}

void GlobalConnectionManager::removeConnection(Connection *pConnection)
{

}

void GlobalConnectionManager::sendData(QIODevice *from, sockTypes to)
{
    transfer = new DataTransfer(this);
    connect(transfer,SIGNAL(sendEnd(bool)),this,SLOT(transferEnd(bool)));
    transfer->send(from,connections[to]);
}

void GlobalConnectionManager::transferEnd(bool isError)
{
    if(isError) qDebug() << "transfer file: error";
    else qDebug() << "transfer file: success";
    emit sendEnd();
}
